Ext.require([ 
    'Ext.grid.*', 
    'Ext.toolbar.Paging', 
    'Ext.util.*', 
    'Ext.data.*'  
]);  
Ext.onReady(function(){ 
    Ext.define('MyData',{ 
        extend: 'Ext.data.Model', 
        fields: [{name:"Jcd_mc"},{name:"JKXT_MN"},{name:"Datatime"},{name:"Avalue"},
		               {name:"Flag"},{name:"DataState"}
    ]})
var flag=true;
var mn;
var oldMc=null;
//监测点树数据源
var storetree = Ext.create('Ext.data.TreeStore', {
proxy:{
		type:'ajax',
		url:path+'/sssj/sssj/hs_getDcfsHjjcdJbxxListByCond.action'
	},
	autoLoad:true
});
 // 创建数据源
    var store = Ext.create('Ext.data.Store', { 
        model: 'MyData', 
        remoteSort:true,
        proxy: { 
           // 异步获取数据，这里的URL可以改为任何动态页面，只要返回JSON数据即可
            type: 'ajax', 
            url: path+'/sssj/sssj/hs_getDcfsHsEmstimeListByCond.action', 
            reader: { 
                type: 'json', 
                root: 'root'
            } 
        }
    });
//监测点所树
var treeW=Ext.create('Ext.tree.Panel', {
	border:false,
	region : 'west',
	store: storetree,
	rootVisible: false,
	split : true,
	width : 200,
	minSize : 220,
	autoScroll : true,
	listeners:{
	'itemclick':function(view,record, item, index, e, eOpts ){
		flag=record.get("leaf");
		mn=record.get("id");
	if(record.get("leaf")==true){
		oldMc=record.get("text");
		store.load({ params:{"dcfsHsEmstime.jkxtmn": record.get("id"),"flag":"2"}});
		Ext.getCmp("cChart").setHeight(250);
		Ext.getCmp("cChart").body.update('<iframe id="chartF" name="chartF" src="'+path+'/sssj/sssj/hs_chart.action?dcfsHsEmstime.jkxtmn='+record.get("id")+'" width="100%" height="570px" scrolling="no" frameborder="0" ></iframe>');
	}else{
		store.load({ params:{"dcfsHjjcdJbxx.jkxtmn": record.get("id"),"flag":"1"}});
		Ext.getCmp("cChart").body.update('');
		Ext.getCmp("cChart").setHeight(0);
		Ext.getCmp("cChart").hide;
	}
	},
	'load':function(tree, node, records, successful, eOpts){
		var Wid=treeW.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0);
		treeW.getSelectionModel().select(Wid);
		mn=Wid.get("id");
		oldMc=Wid.get("text");
		store.load({ params:{"dcfsHsEmstime.jkxtmn": mn,"flag":"2"}});
		Ext.getCmp("cChart").setHeight(250);
		Ext.getCmp("cChart").body.update('<iframe id="chartF" name="chartF" src="'+path+'/sssj/sssj/hs_chart.action?dcfsHsEmstime.jkxtmn='+mn+'" width="100%" height="570px" scrolling="no" frameborder="0" ></iframe>');
	}
	}
});
var jcsj_grid=new Ext.grid.GridPanel({
        title: '数据列表',
    	id:'jcsj_grid',
        columnLines: true, 
    	border: true,
    	forceFit : true,
        store: store, 
        columns: [
        	  {text:"设备名称",dataIndex:"Jcd_mc", sortable: false,
        	  renderer:function(value){
	          	if(value==null||value=="null"){
	          		return oldMc;
	          	}else{
					return value;          	
		        }
	          }
	          },
              {text:"设备标识",dataIndex:"JKXT_MN", sortable: false},
	          {text:"时间",dataIndex:"Datatime", sortable: false,
	          renderer:function(value){
	          	if(value==null||value=="null"){
	          		return "";
	          	}else{
					return value;          	
		        }
	          }
	          },
	          {text:"强度E（V/m）",dataIndex:"Avalue", sortable: false,
	          renderer:function(value){
	          	if(value==null||value=="null"){
	          		return "";
	          	}else{
					return value;          	
		        }
	          }
	          }
        ], 
        viewConfig: { 
            stripeRows: true
        },
        listeners:{
            	itemdblclick: function(grid){
            }
            }
});
var test=new Ext.panel.Panel({
		region : 'center',
		height:258,
		autoScroll : true,
		border:false,
    	items:[
    		{
    		xtype:'form',
    		border:false,
    		autoScroll : true,
    		items:[{
    		xtype:'panel',
			id:'cChart',
			name:'cChart',
			html:''
    		},
    		jcsj_grid
    		]
    	}]
})
//放射源管理页面
var ssjk=new Ext.panel.Panel({
    layout : 'border',
    items:[
    treeW,test
    ]
    });
var refresh=function() 
{ 
   if(flag==true){
		store.load({ params:{"dcfsHsEmstime.jkxtmn": mn,"flag":"2"}});
		Ext.getCmp("cChart").setHeight(250);
		Ext.getCmp("cChart").body.update('<iframe id="chartF" name="chartF" src="'+path+'/sssj/sssj/hs_chart.action?dcfsHsEmstime.jkxtmn='+mn+'" width="100%" height="570px" scrolling="no" frameborder="0" ></iframe>');
	}else{
		store.load({ params:{"dcfsHjjcdJbxx.jkxtmn": mn,"flag":"1"}});
		Ext.getCmp("cChart").body.update('');
		Ext.getCmp("cChart").setHeight(0);
		Ext.getCmp("cChart").hide;
	}
} 
setInterval(refresh,300000); //指定1秒刷新一次  
//显示 
Ext.create('Ext.Viewport', {
    	layout:'fit',
    	items:ssjk
       }) 
});
